package com.wits100.demoplayer;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class PlaybackActivity extends AppCompatActivity {

    public final  String TAG = "player";

    private VideoView videoView;
    private MediaController mediaController;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//去掉信息栏

        setContentView(R.layout.activity_playback);

        setupPlayer();


        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        if (url != null) {
            startPlay(url);
        }

    }

    @Override
    protected void onStop() {

        videoView.stopPlayback();

        super.onStop();
    }


    private void setupPlayer() {
        videoView = (VideoView) findViewById(R.id.videoView);
        mediaController = new MediaController(this);
        videoView.setMediaController(mediaController);
        videoView.requestFocus();
    }


    public void startPlay(String url) {
        videoView.setVideoURI(Uri.parse(url));
        videoView.start();
    }



    public void onClickReturn(View view) {
        Log.i(TAG, "return ...");

        finish();
    }

}
